<template>
  <view class="content pb-50">
    <view v-if="JSON.stringify(list) != '[]'" class="list-block pl-20 pr-20">
      <view class="item-block pd-30 mt-20" v-for="(item, index) in list" :key="index" @click="checkItem(item.type, item.id, item.guardianAudit)">
        <view class="info-block">
          <view class="item-title" style="width: 420rpx;"><text class="item-index mr-10">{{index + 1}}.</text>{{item.name ? item.name : '-'}}({{item.content ? item.content : ''}})</view>
          <view class="item-subtitle">类型：{{item.type ? typeList[item.type] : '-'}}</view>
        </view>
        <view class="info-block mt-40">
          <view class="item-info">申请人：{{item.applicant ? item.applicant : '-'}}</view>
          <view class="item-info">创建时间：{{item.createTime ? item.createTime : '-'}}</view>
        </view>
      </view>
    </view>
    <view v-else class="empty-block">
      <u-empty text="暂无数据" mode="data" icon-size="80"></u-empty>
    </view>
  </view>
</template>

<script>
  import { getWaitListApi } from '@/apis/work/index.js'
  import { getDictListApi } from '@/apis/work/common.js'
  
  export default {
    data() {
      return {
        list: [],
        typeList: {}
      }
    },
    onShow() {
      this.getWorkTypeList()
    },
    methods: {
      getWorkTypeList: function() {
        getDictListApi('licence_type').then(res => {
          let typeList = {}
          if(res.length > 0) res.map(item => Object.assign(typeList, { [item.value]: item.label }))
          this.typeList = typeList
          this.getWaitList()
        }).catch(err => console.warn(err))
      },
      getWaitList: function() {
        getWaitListApi().then(res => {
          this.list = res
        }).catch(err => console.warn(err))
      },
      checkItem: function(type, id, state) {
        if (type == '1') {
          uni.navigateTo({ url: `/pagesWork/workCreateHot?type=${type}&id=${id}&serviceType=check&guardianAudit=${state ? 1 : 0}` })
        } else if (type == '2') {
          uni.navigateTo({ url: `/pagesWork/workCreateSpace?type=${type}&id=${id}&serviceType=check&guardianAudit=${state ? 1 : 0}` })
        } else if (type == '3') {
          uni.navigateTo({ url: `/pagesWork/workCreateBlindPlate?type=${type}&id=${id}&serviceType=check&guardianAudit=${state ? 1 : 0}` })
        } else if (type == '4') {
          uni.navigateTo({ url: `/pagesWork/workCreateHigh?type=${type}&id=${id}&serviceType=check&guardianAudit=${state ? 1 : 0}` })
        } else if (type == '5') {
          uni.navigateTo({ url: `/pagesWork/workCreateHoisting?type=${type}&id=${id}&serviceType=check&guardianAudit=${state ? 1 : 0}` })
        } else if (type == '6') {
          uni.navigateTo({ url: `/pagesWork/workCreateElectric?type=${type}&id=${id}&serviceType=check&guardianAudit=${state ? 1 : 0}` })
        } else if (type == '7') {
          uni.navigateTo({ url: `/pagesWork/workCreateDigging?type=${type}&id=${id}&serviceType=check&guardianAudit=${state ? 1 : 0}` })
        } else if (type == '8') {
          uni.navigateTo({ url: `/pagesWork/workCreateRoad?type=${type}&id=${id}&serviceType=check&guardianAudit=${state ? 1 : 0}` })
        } else {
          uni.showToast({ title: `未找到${this.activeName}作业页面`, icon: 'none' })
        }
      }
    }
  }
</script>

<style>
  page {
    background-color: #EFEFEF;
  }
</style>

<style lang="scss" scoped>
  .content {
    .item-block {
      background-color: #FFFFFF;
      border-radius: 10rpx;
      .info-block {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .item-title {
        font-size: 30rpx;
        line-height: 42rpx;
        color: #333333;
        font-weight: 500;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding-right: 20rpx;
        .item-index {
          color: #0883F8;
        }
      }
      .item-subtitle {
        font-size: 28rpx;
        line-height: 40rpx;
        color: #666666;
        font-weight: 500;
      }
      .item-info {
        font-size: 24rpx;
        line-height: 32rpx;
        color: #666666;
      }
    }
    .empty-block {
      padding-top: 300rpx;
    }
  }
</style>